import sys

from PyQt5.QtGui import QColor
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QFrame, QVBoxLayout, QHBoxLayout, \
    QCheckBox, QSlider, QProgressBar
from PyQt5.QtCore import Qt, QBasicTimer

'''
QProgressBar 进度条控件  最小最大值设置 0-100
QBasicTimer - timeEvent 时钟控件 ，单位毫秒 isActive()返回时钟控件是否开启True/False  start(时间，self) stop() timerId()
按钮状态：开始 停止（暂停）完成 ，并控制进度条
'''


class MyClass(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程')
        self.setGeometry(800, 370, 400, 300)

        self.pgb = QProgressBar(self)
        self.pgb.move(50, 50)
        self.pgb.resize(300, 20)
        self.pgb.setMinimum(0)
        self.pgb.setMaximum(100)
        self.pv = 0
        self.pgb.setValue(self.pv)

        self.btn = QPushButton('开始', self)
        self.btn.move(150, 100)
        self.btn.clicked.connect(self.myTimer)

        self.timer1 = QBasicTimer()

        self.show()

    def myTimer(self):
        if self.timer1.isActive():
            self.timer1.stop()
            self.btn.setText('继续')
        else:
            self.timer1.start(100, self)  # 执行间隔500ms
            self.btn.setText('暂停')
            if self.pv > 100:
                self.pv = 1

    def timerEvent(self, e):
        if self.pv == 100:
            self.timer1.stop()
            self.btn.setText('完成')
        self.pv += 1
        self.pgb.setValue(self.pv)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myf = MyClass()
    app.exec_()
